Bite 211. Write a retry decorator
Login and get codingWrite a
retrydecorator that retries executing the function it decorates. If the function raises an exception (any kind) it tries again, until it reachesMAX_RETRIES(set to 3) at which point it throws aMaxRetriesExceptionexception (already defined).In the tests we define
get_two_numbersto test this. It gets a list of numbers which may contain bad data (nonints orfloats). It tries to pick 2 random numbers from this list but if both those numbers are notints, it raises aValueErrorin which case the retry decorator would run the function again.Check out the template's docstring as well as the tests for more details. Good luck and keep calm and code in Python!
148 out of 150 users completed this Bite.
Will you be the 149th person to crack this Bite?
Resolution time: ~33 min. (avg. submissions of 5-240 min.)
Our community rates this Bite 4.85 on a 1-10 difficulty scale.
» Up for a challenge? 💪